public class Linkedlist {
    public static void main(String[] args) {
        HeroNode heroNode = new HeroNode(1, "W", "B");
        HeroNode heroNode2 = new HeroNode(2, "D", "W");
        HeroNode heroNode3 = new HeroNode(3,"J","D");
        linked linked = new linked();
        linked.add(heroNode3);
        linked.add2(heroNode2);
        linked.add2(heroNode);
        HeroNode heroNode1 = new HeroNode(2,"I","G");
        linked.update(heroNode1);
        linked.del(1);
        linked.select(2);
        linked.list();
    }
}
//massage
class linked{
    //初始化结点
    private HeroNode head =new HeroNode(0,"","");

    public void add(HeroNode heroNode){
        HeroNode temp = head;
        while (true){
            if (temp.next==null){break;}
            temp = temp.next;
        }
        temp.next = heroNode;
    }
    public void list(){
        if (head.next==null){
            System.out.println("list is null");
            return;
        }
        HeroNode t = head.next;
        while (true){
            if (t==null){break;}
            System.out.println(t);
            t = t.next;
        }
    }
    void add2(HeroNode heroNode){
        HeroNode temp = head;
        boolean flag = false;
        while (true){
            if (temp.next==null){break;}
            if (temp.next.no>heroNode.no){break;} else if (temp.next.no==heroNode.no) {flag=true;break;}
            temp = temp.next;
        }
        if (flag){System.out.println("no is create"+heroNode.no);}
        else {heroNode.next=temp.next;temp.next=heroNode;}
    }
    public void update(HeroNode heroNode){
        if (head.next==null){
            System.out.println("list is null");
        }
        HeroNode temp =head.next;
        boolean flag = false;
        while (true){
            if (temp==null){
                break;
            }
            if (temp.no==heroNode.no){
                flag = true;
                break;
            }
            temp = temp.next;
        }
        if (flag){
            temp.name = heroNode.name;
            temp.nickname = heroNode.nickname;
        }else {
            System.out.println("not find");
        }
    }
    public void del(int no){
        if (head.next==null){
            System.out.println("list is null");
        }
        HeroNode temp =head;
        boolean flag = false;
        while (true){
            if (temp.next==null){
                break;
            }
            if (temp.next.no==no){
                flag = true;
                break;
            }
            temp = temp.next;
        }
        if (flag){
            temp.next=temp.next.next;
        }else {
            System.out.println("not find of no");
        }
    }
    public void select(int no){
        if (head.next==null){
            System.out.println("list is null");
        }
        HeroNode temp =head;
        boolean flag = false;
        while (true){
            if (temp.next==null){
                break;
            }
            if (temp.no==no){
                flag = true;
                break;
            }
            temp = temp.next;
        }
        if (flag){
            System.out.println(temp);
        }else {
            System.out.println("not find of no");
        }
    }
}

//定义node\
class HeroNode{
    public int no;
    public String name;
    public String nickname;
    public HeroNode next;

    public HeroNode(int no, String name, String nickname) {
        this.no = no;
        this.name = name;
        this.nickname = nickname;
    }

    @Override
    public String toString() {
        return "HeroNode{" +
                "no=" + no +
                ", name='" + name + '\'' +
                ", nickname='" + nickname  +"'"+
                '}';
    }
}
